package com.xinzhi.dao;

import java.sql.*;













   class BaseDao {
    //数据库表的具体位置
    private static String url = "jdbc:mysql://localhost:3306/shan?characterEncoding=UTF-8";
    //用户名
    private static String username = "root";
//    密码
    private static String pwd = "123456";
    //给调用方法建立通道
    private static Connection conn;

    /**
     * 加载连接数据库包和sql语句处理
     * @return
     */
    public static Connection getConn() {
        try {
            //加载驱动类
            Class.forName("com.mysql.cj.jdbc.Driver");
            conn = DriverManager.getConnection(url, username, pwd);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return conn;
    }

    /**
     * 关闭连接数据库数据
     * @param rs
     * @param stat
     * @param conn
     */
    public static void closeAll(ResultSet rs, Statement stat, Connection conn) {
        try {
            if (rs != null)
                rs.close();
            if (stat != null)
                stat.close();
            if (conn != null);
                conn.close();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }
}
